﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QLNS.aspFrm
{
    public partial class frmQuaTrinhDaoTao : System.Web.UI.Page
    {
        public string IDCB { get { return Request.QueryString["id"].ToString(); } }
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Data.DataTable dtTK = MakeTable();
            //doan nay co the bo 
            List<QLNS.DaoTao> lstTK = QLNS.Models.DaoTaoModels.GetQuaTrinhDaoTaoTheoCanBo(Convert.ToInt32(Request["id"].ToString()));
            foreach (var r in lstTK)
            {
                System.Data.DataRow row;
                row = dtTK.NewRow();
                this.FillDataRow(row, r);
                dtTK.Rows.Add(row);
            }

            //Tao 5 level cho phong ban


            CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            string strRptPath = Server.MapPath("~/") + "Reports//Report_QuaTrinhDaoTao.rpt";
            //Loading Report
            rd.Load(strRptPath);

            // Setting report data source
            if (dtTK != null && dtTK.GetType().ToString() != "System.String")
                rd.SetDataSource(dtTK);


            CrystalReportViewer1.ReportSource = rd;
        }
        private void FillDataRow(System.Data.DataRow row, QLNS.DaoTao r)
        {
            //System.Data.DataRow row = new System.Data.DataRow();

            System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB");

            row["ChuyenNganh"] = r.ChuyenNganh;
            row["NoiDaoTao"] = r.NoiDaoTao;
            row["HinhThucDaoTao"] = r.HinhThucDaoTao;
            row["ChungChi"] = r.ChungChi;
            if (r.TuNgay == DateTime.Parse("01/1/1900"))
            {
                row["TuNgay"] = "";
            }
            else
            {
                string[] words = r.TuNgay.ToString().Split(' ');
                //s = s.Substring(0, 10);
                row["TuNgay"] = words[0];
            }

            if (r.DenNgay == DateTime.Parse("01/1/1900"))
            {
                row["DenNgay"] = "";
            }
            else
            {
                string[] wordss = r.DenNgay.ToString().Split(' ');
                //s = s.Substring(0, 10);
                row["DenNgay"] = wordss[0];
            }
            //row["TuNgay"] = r.TuNgay.ToString() == "" ? DateTime.Parse("01/1/1900", ci.DateTimeFormat) : r.TuNgay;
            //row["DenNgay"] = r.DenNgay.ToString() == "" ? DateTime.Parse("01/1/1900", ci.DateTimeFormat) : r.DenNgay;


            //return row;
        }
        private System.Data.DataTable MakeTable()
        {
            // Create a new DataTable.
            System.Data.DataTable table = new System.Data.DataTable("Table");

            // Declare variables for DataColumn and DataRow objects.
            System.Data.DataColumn column;

            // Create new DataColumn, set DataType, 


            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ChuyenNganh";
            column.Caption = "Chuyên ngành";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NoiDaoTao";
            column.Caption = "Nơi đào tạo";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "HinhThucDaoTao";
            column.Caption = "Hình thức đào tạo";
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ChungChi";
            column.Caption = "Chứng chỉ";
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TuNgay";
            column.Caption = "Từ ngày";
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "DenNgay";
            column.Caption = "Đến ngày";
            // Add the column to the table.
            table.Columns.Add(column);


            return table;
        }
    }
}